<?php
class Default_Form_ValidateCheckout{
	//CHUA NHUNG THONG BAO LOI CUA FORM
	protected $_messagesError = null;
	//MANG CHUA DU LIEU SAU KHI KIEM TRA
	protected $_arrData;
	
	public function __construct($arrParam = array(),$options = null){
		$validator = new Zend_Validate();
		$validator->addValidator(new Zend_Validate_NotEmpty(),true)
				  ->addValidator(new Zend_Validate_EmailAddress(),true);
		if(!$validator->isValid($arrParam['email'])){
			$message = $validator->getMessages();
			$this->_messagesError['email'] = current($message);
		}		
		
		$validator = new Zend_Validate();
		$validator->addValidator(new Zend_Validate_NotEmpty(),true)
				  ->addValidator(new Zend_Validate_StringLength(3, 200));
		if(!$validator->isValid($arrParam['name'])){
			$message = $validator->getMessages();
			$this->_messagesError['name'] = current($message);
		}
		
		$validator = new Zend_Validate();
		$validator->addValidator(new Zend_Validate_NotEmpty(),true)
				  ->addValidator(new Zend_Validate_StringLength(2, 250));
		if(!$validator->isValid($arrParam['address'])){
			$message = $validator->getMessages();
			$this->_messagesError['address'] = current($message);
		}

		$validator = new Zend_Validate();
		$validator->addValidator(new Zend_Validate_NotEmpty(),true);
		if(!$validator->isValid($arrParam['phone'])){
			$message = $validator->getMessages();
			$this->_messagesError['phone'] = current($message);
		}
		
		if(!empty($arrParam['comment'])){
			$validator = new Zend_Validate();
			$validator->addValidator(new Zend_Validate_StringLength(2));
			if(!$validator->isValid($arrParam['comment'])){
				$message = $validator->getMessages();
				$this->_messagesError['comment'] = current($message);
			}
		}

		$this->_arrData = $arrParam;

	}

	public function isError(){	
		if(count($this->_messagesError)>0){
			return true;
		}else{
			return false;
		}
	}

	public function getMessageError(){
		return $this->_messagesError;
	}

	public function getData($options = null){
		return $this->_arrData;
	}
}